package com.wudi.estate.service.impl.admin;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.wudi.estate.bean.admin.Admin;
import com.wudi.estate.mapper.admin.AdminMapper;
import com.wudi.estate.service.admin.AdminService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class AdminServiceImpl implements AdminService {
    @Autowired
    private AdminMapper adminMapper;
    @Override
    public Admin selectOneByName(String username) throws Exception {
        QueryWrapper<Admin> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("username",username);
        Admin admin = adminMapper.selectOne(queryWrapper);
        return admin;
    }
    @Override
    public List<Map<String, Object>> selectAllAdminAndRoles() throws Exception {
        return adminMapper.selectAllAdminAndRoles();
    }

    @Override
    public void insert1(Admin admin) throws Exception {
        adminMapper.insert(admin);
    }

    @Override
    public PageInfo<Map<String, Object>> getPageInfo(int pageNum, int pageSize) throws Exception {

        PageHelper.startPage(pageNum, pageSize);

        List<Map<String, Object>> adminAndRoles = adminMapper.selectAllAdminAndRoles();
        PageInfo<Map<String, Object>> pageInfo = new PageInfo<>(adminAndRoles);

        return pageInfo;
    }
}
